#!/bin/bash

# Install Docker CE
## Set up the repository
### Install required packages.
    yum install -y yum-utils device-mapper-persistent-data lvm2

### Add docker repository.
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# yum-config-manager \
#     --add-repo \
#     https://download.docker.com/linux/centos/docker-ce.repo

## Install docker ce.
yum -y update && yum install -y docker-ce-18.06.2.ce

## Create /etc/docker directory.
mkdir /etc/docker

# Setup daemon.
cat > /etc/docker/daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
     "max-size": "100m"
   },
   "storage-driver": "overlay2",
   "storage-opts": [
     "overlay2.override_kernel_check=true"
   ]
}
EOF

mkdir -p /etc/systemd/system/docker.service.d
tee /etc/systemd/system/docker.service.d/devicemapper.conf <<-'EOF'
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd  --graph=/opt/docker/lib
EOF

# Restart docker.
systemctl daemon-reload
systemctl restart docker
systemctl enable docker